package com.permission.dao.impl;

import com.permission.dao.PerRoleDao;
import com.permission.model.PerRole;
import com.solution.framework.dao.impl.BaseDaoImpl;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * Created with generator tools.
 * User: sunguangzhu
 * DateTime:2014-05-07 12:48:37
 */

@Repository
public class PerRoleDaoImpl extends BaseDaoImpl<PerRole> implements PerRoleDao {
    @Override
    public List<PerRole> getAvaliblePerRoles(final Long perUserId) {
        final String hql = "from PerUserRole pur where pur.perUser.id = :perUserId ";
        return (List<PerRole>) this.getHibernateTemplate().execute(new HibernateCallback() {
            public List<PerRole> doInHibernate(Session session) throws HibernateException, SQLException {
                Query query = session.createQuery(hql);
                query.setParameter("perUserId",perUserId);
                return query.list();
            }
        });
    }

    @Override
    public List<PerRole> getInAvaliblePerRoles(Long perUserId) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
